package com.hsy.baoinbao.modules.main.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.deparse.dpframe.utils.DPGsonUtil;
import com.deparse.dpframe.utils.DPHttpUtil;
import com.deparse.dpframe.utils.DPLogUtil;
import com.hsy.baoinbao.R;
import com.hsy.baoinbao.common.Consts;
import com.hsy.baoinbao.modules.common.CommonBaseActivityWithSimpleActionBar;
import com.hsy.baoinbao.modules.order.activity.DetailReceivingActivity;
import com.hsy.baoinbao.utils.CommonUtils;
import com.hsy.baoinbao.utils.HttpUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/4/15.
 */
public class IntoStepSecondActivity extends CommonBaseActivityWithSimpleActionBar {
    private TextView name_merchant, name, user_name, address, finish;
    private String phone = null;
    private String userId = null;
    private DPHttpUtil.HttpCallback callBack = new DPHttpUtil.HttpCallback() {
        @Override
        public void onSuccess(int what, String response) {
            if (0 == what) {
                IntoGsonData.Result result = DPGsonUtil.fromJson(response, IntoGsonData.Result.class);
                CommonUtils.hideProgressDialog();
            }
            if (1 == what) {
                try {
                    CommonUtils.hideProgressDialog();
                    JSONObject result = new JSONObject(response);
                    String id = result.optString("id");
                    Intent intent = new Intent(IntoStepSecondActivity.this, DetailReceivingActivity.class);
                    intent.putExtra("id", id);
                    startActivity(intent);

                } catch (JSONException e) {
                    e.printStackTrace();
                }


            }

        }

        @Override
        public void onError(int what, int type, VolleyError error) {
            CommonUtils.hideProgressDialog();
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_into_person_information);
        setTitle("用户信息");
        Intent intent = getIntent();
        phone = intent.getStringExtra("phone");
        if (isEmpty(phone)) {
            DPLogUtil.d("Phone==null");
        } else {
            Map<String, String> data = new HashMap<>();
            data.put("token", CommonUtils.getToken(this));
            data.put("user_name", phone);
            HttpUtil.httpPostWithParams(this, 0, Consts.API_POST_ORDER_SEARCH, data, callBack);
        }


        name_merchant = F(R.id.name_merchant);
        name = F(R.id.name);
        user_name = F(R.id.user_name);
        address = F(R.id.address);
        finish = F(R.id.finish);

        finish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isEmpty(userId)) {
                    return;
                } else {
                    Map<String, String> data = new HashMap<>();
                    data.put("token", CommonUtils.getToken(IntoStepSecondActivity.this));
                    data.put("uid", userId);
                    HttpUtil.httpPostWithParams(IntoStepSecondActivity.this, 1, Consts.API_POST_ORDER_CONFIRM, data, callBack);

                }

            }
        });

    }

}
